#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    int largestPerimeter(vector<int>& A) {
        if (A.size() < 3) {
            return 0;
        }
        sort(A.begin(), A.end());
        for (int i = A.size() - 3; i >= 0; --i) {
            if ((A[i] + A[i + 1] > A[i + 2]) &&( A[i + 2] - A[i + 1] < A[i]) && (A[i + 2] - A[i] < A[i +1])) {
                return A[i] + A[i + 1] + A[i + 2];
            }
        }
        return 0;
    }
};

//int main() {
//    vector<int> A = { 3,6,2,3 };
//    Solution S;
//    int T = S.largestPerimeter(A);
//    cout << T << endl;
//}

